< previous page page_99 next page >

Page 99
Palette-Relative RGB Values
The second method for specifying palette colors is to use a palette-relative RGB value. To do this, pass to a drawing routine the normal RGB value of the color you want, plus &H2000000. The system maps your color to the closest value in the logical color map. This method is similar to using ordinary RGB values, except Visual Basic does not dither to approximate colors. When it cannot match a color exactly, the program uses the closest color available in the color palette.
When you fill a rectangle, circle, or other shape using a palette-relative RGB value, Visual Basic does not dither the area, even if dithering might produce a better result. For example, suppose you are using the default, static color palette and you want to fill a circle using the color salmon pink. If you specify the color as RGB (255, 127, 127), Visual Basic dithers the area using red with white dots to produce a reasonable approximation of pink.
If you specify the color as &H2000000 + RGB(255, 127, 127), Visual Basic fills the area completely with the color in the logical palette that most closely matches the color you requested. In the default palette, that color is red. Depending on your application, the dithered pink may look better than solid red. When you specify palette-relative RGB values, you assume the responsibility for ensuring that the colors in your palette produce a satisfactory result.
Example program Relative, shown in Figure 3.7, demonstrates palette-relative RGB values using the system static colors. The program fills the picture box on the left with various shades of red, green, and blue specified using the RGB function. Because this picture box uses the default static palette, Visual Basic dithers to produce approximations of the colors.
The program fills the picture box on the right with the same colors using palette-relative RGB values. Visual Basic selects the colors in the static palette that match the specified colors most closely. The result is not as grainy as the dithered version, but the colors form large blocky regions.
0099-01.jpg
Figure 3.7
Example program Relative displays dithered and
palette-relative colors.

 
< previous page page_99 next page >